<script setup lang="ts">
import { reactive, ref } from "vue";
import { addHost } from "@/api/vap/shhost.ts";

const emit = defineEmits(["onSearchEvn"]);

const form = reactive({
  uid: "",
  hostName: "",
  ip: "",
  connPort: 22,
  authType: 1,
  username: "",
  password: "",
  remark: ""
});

const dialogVisible = ref(false);
const showDialog = () => {
  dialogVisible.value = true;
};

const clickAddBtn = () => {
  form.connPort = Number(form.connPort);
  addHost(form).then(() => {
    dialogVisible.value = false;
    emit("onSearchEvn");
  });
};

defineExpose({
  showDialog
});
</script>

<template>
  <el-dialog v-model="dialogVisible" title="添加sh主机" width="500">
    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="主机ID">
        <el-input v-model="form.uid" />
      </el-form-item>
      <el-form-item label="主机名称">
        <el-input v-model="form.hostName" />
      </el-form-item>
      <el-form-item label="主机IP">
        <el-input v-model="form.ip" />
      </el-form-item>
      <el-form-item label="连接端口">
        <el-input v-model="form.connPort" />
      </el-form-item>
      <el-form-item label="验证方式">
        <el-radio-group v-model="form.authType">
          <el-radio :label="1">默认账户</el-radio>
          <el-radio :label="2">实时输入</el-radio>
          <el-radio :label="3">预设凭证</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="默认账户">
        <el-input v-model="form.username" />
      </el-form-item>
      <el-form-item label="默认密码">
        <el-input v-model="form.password" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.remark" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="clickAddBtn"> 提交 </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style scoped></style>
